package com.mlc.core.serviceImpl;

import com.mlc.data.entity.Syslogs;
import com.mlc.data.dao.SyslogsDao;
import com.mlc.core.service.SyslogsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author FireWang
 * @date 2022/03/14 02:46:46
 */
@Service
@AllArgsConstructor
@Transactional
public class SyslogsServiceImpl implements SyslogsService {
    private SyslogsDao syslogsDao;

    @Override
    public List<Syslogs> getAll() {
        return syslogsDao.findAll();
    }

    @Override
    public Syslogs getById(Integer id) {
        Optional<Syslogs> syslogs = syslogsDao.findById(id);
        return syslogs.get();
    }

    @Override
    public void insert(Syslogs syslogs) {
        syslogs.setCreateTime(new Date());
        syslogsDao.save(syslogs);
    }

    @Override
    public void update(Syslogs syslogs) {
        syslogsDao.save(syslogs);
    }

    @Override
    public void deleteById(Integer id) {
        syslogsDao.deleteById(id);
    }
}